package doan.chuyennganh.model;

import java.util.ArrayList;

public class ListStudent {
	private String classID = "";
	private static ListStudent listStudent = null; 
	private AttendanceList attendanceList = null;
	private ArrayList<Student> list = null;
	
	public void setList( ArrayList<Student> list) {
		this.list = list;
	}
	public  ArrayList<Student>  getAllStudents() {
		return list;
	}
	public Student getStudent(String id){
		for (Student st : list) {
			if(st.getMaSV().equals(id)){
				return st;
			}
		}
		return null;
	}
	public boolean isContains(Student student){
		if(list.contains(student)){
			return true;
		}
		return false;
	}
	public boolean isContains(String studentID){
		for(Student st : list)
		if(st.getMaSV().equalsIgnoreCase((studentID))){
			return true;
		}
		return false;
	}
	public int addStudent(Student student) {
		if(list.contains(student)){
			return 0;
		}
		list.add(student);
		return 1;
	}
	public int removeStudent(String studentID) {
		Student st = getStudent(studentID); 
		if( st == null){
			return 0;
		}
		list.remove(st);
		return 1;
	}
	public int updateStudent(Student student) {
		Student st = getStudent(student.getMaSV()); 
		if( st == null){
			return 0;
		}
		list.add(list.indexOf(st), student);
		list.remove(st);
		return 1;
	}
	private ListStudent(){
		list = new ArrayList<Student>();
		attendanceList = new AttendanceList();
	}
	public static synchronized ListStudent getInstance() {
		if(listStudent == null){
			listStudent = new ListStudent();
		}
		return listStudent;
	}
	public String getClassID() {
		return classID;
	}
	public void setClassID(String classID) {
		this.classID = classID;
	}
	public int size(){
		return list.size();
	}
	public AttendanceList getAttendanceList() {
		return attendanceList;
	}
	public void setAttendanceList(AttendanceList attendanceList) {
		this.attendanceList = attendanceList;
	}
}
